def grade(anwser, right_anwser):
    score = 0
    i = 0
    while i < len(right_anwser):
        if right_anwser[i] == anwser[i]:
            score += 1
        else:
            pass
        i += 1
    return score


def get_cheats_students():
    file_sel = open('作弊学生名单.txt', 'r')  # 打开学生选择题文件,  r代表只读
    s = set()
    for line in file_sel.readlines():
        s.add(line.strip())
    return s


def get_scores():
    score_map = {}
    file_sel = open('学生选择题选项.txt', 'r')  # 打开学生选择题文件,  r代表只读
    for line in file_sel.readlines():  # 读文件
        line = line.strip()
        ss = line.split(',')
        anwser = ss[1]
        stu_no = ss[0]
        score = grade(anwser, right_ansmer)
        score_map[stu_no] = score
    return score_map


right_ansmer = 'ADACDBCBCD'

if __name__ == '__main__':
    print('得分:', grade('ADACDBCBCD', 'ADACDBCBCD'))
    right_ansmer = 'ADACDBCBCD'
    print('得分:', grade('ADACDBCBCA', 'ADACDBCBCD'))

    score_map = get_scores()
    print('学生分数:', score_map)
    cheats_stus = get_cheats_students()
    print('作弊学生名单:', cheats_stus)
    for k in cheats_stus:
        score_map[k] = 0
    total = 0
    for k, v in score_map.items():
        total += v
    stu_nums = len(score_map)
    print('平均分:', total / stu_nums)

    jg_total = 0
    for k, v in score_map.items():
        if v >= 5:
            jg_total += 1
    print('及格的人数:', jg_total)
